/**
 *  All error codes used throughout the system
 *
 *  @author Scott Monahan
 *  @version $Id$
 *  
 *  File last changed on $Date:$ by $Author:$ in $Rev:$
 *
 */

package info637.pprc;

public enum ErrorCodes {
	
	UNKNOWN(-1),
	
	// Field level validations
	
	SESSION_ID_REQUIRED(100001),
	REQUEST_ID_REQUIRED(100002),
	INVALID_USER_NAME_OR_PASSWORD(100020),
	USER_NAME_REQUIRED(10021),
	PASSWORD_REQUIRED(100031),
	PROPERTY_NAME_REQUIRED(100041),
	PROPERTY_ADDRESS_REQUIRED(100051),
	PROPERTY_CITY_REQUIRED(100061),
	PROPERTY_STATE_REQUIRED(100071),
	PROPERTY_ZIP_REQUIRED(100081),
	INVALID_MONTHLY_RENT(100090),
	PROPERTY_MONTHLY_RENT_REQUIRED(100091),
	INVALID_SECURITY_DEPOSIT(100100),
	INVALID_NUM_OF_BEDS(100110),
	INVALID_NUM_OF_BATHS(100120),
	INVALID_SQFT(100130),
	CONTACT_INFO_REQUIRED(100141),
	INVALID_SHOW_ONLINE_FLAG(100150),
	INVALID_SHOW_IN_FLYER_FLAG(100160),
	PROPERTY_ID_REQUIRED(100171),
	INVALID_BALANCE(100180),
	
	// Service level validations
	
	SESSION_EXPIRED(200001),
	PROPERTY_ALREADY_EXISTS(200002),
	PROPERTY_NOT_FOUND(200003),
	PROPERTY_REPOSITORY_EMPTY(200004);
	
	private int errorCode = 0;
	
	ErrorCodes(int errorCode) {
		
		this.errorCode = errorCode;
	}
	
	public int getErrorCode() {
		
		return this.errorCode;
	}
	
	public String asString() {
		
		return Integer.toString(this.errorCode);
	}
	
	public static ErrorCodes fromString(String val) {

		if (val != null) {

			for (ErrorCodes b : ErrorCodes.values ()) {
				
				if (val.equalsIgnoreCase (b.asString ())) {

					return b;
				}
			}
		}

		return UNKNOWN;
	}
}
